<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
	<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
	<title></title>
	<script type="text/javascript" src="../../js/boot.js"></script>
</head>

<body>
	<div style="width:100%;height:14%;">
		<fieldset id="fd1" style="width: 97%; margin-bottom: 10px;">
			<legend><span>查询条件</span></legend>
			<div id="queryForm" class="fieldset-body">
				<table class="form-table" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td class="form-label">
							<span>项目名称：</span>
							<input name="projectName" class="mini-textbox" style="width: 150px" />
							<input name="projectName_link" value="like" class="mini-hidden" style="width: 150px" />
							<a class="mini-button" onclick="doSearch">查询</a>
							<a class="mini-button" onclick="doAdd">新增</a>
							<a class="mini-button" onclick="doEdit">修改</a>
							<a class="mini-button" onclick="doDelete">删除</a>
							<a class="mini-button" onclick="doOrg">组织管理</a>
						</td>
					</tr>
				</table>
			</div>
		</fieldset>

	</div>
	<div style="width:100%;height:86%;">
		<div class="mini-fit">
			<div id="datagrid" class="mini-datagrid" style="width:100%;height:100%;" pageSize="20" allowResize="true">
			</div>
		</div>
	</div>

	<!-- 计算需要显示的控件数量 -->
	<!-- 根据控件数量计算窗体的高度 -->
	<!-- 主键名称 -->
	<div id="detailWin" class="mini-window" title="" style="width:600px;height:280px;" showMaxButton="true" showCollapseButton="true" showShadow="true"
		showToolbar="true" showFooter="true" showModal="true" allowResize="true" allowDrag="true">
		<div id="detailForm" style="padding:10px;">
			<input name="projectID" class="mini-hidden" enabled="false">
			<table align="center">
				<tr>
					<td align="right">项目编号：</td>
					<td align="left"><input name="projectNo" class="mini-textbox"></td>
					<td align="right">项目名称：</td>
					<td align="left"><input name="projectName" class="mini-textbox"></td>
				</tr>
				<tr>
					<td align="right">项目开始时间：</td>
					<td align="left"><input name="startTime" class="mini-datepicker"></td>
					<td align="right">项目结束时间：</td>
					<td align="left"><input name="endTime" class="mini-datepicker"></td>
				</tr>
				<tr>
					<td align="right">技术经理：</td>
					<td align="left">
						<input id="projectUserName" name="projectUserName" class="mini-buttonedit" onbuttonclick="openSelectUserDialog" selectOnFocus="true" />
						<input id="projectUserID" name="projectUserID" class="mini-hidden" />
					</td>
					<td align="right">文档管理员：</td>
					<td align="left">
						<input id="documentUserName" name="documentUserName" class="mini-buttonedit" onbuttonclick="openSelectUserDialog"
							selectOnFocus="true" />
						<input id="documentUserID" name="documentUserID" class="mini-hidden" />
					</td>
				</tr>
				<tr>
					<td align="right">项目分类：</td>
					<td align="left"><input name="type" class="mini-textbox"></td>
					<input class="mini-hidden" name="projectID">
					<td align="right">项目性质：</td>
					<td><input id="projectType" name="projectType" class="mini-combobox" textField="text" valueField="id" data="projectTypes"
							style="width:80%" /></td>
				</tr>
				<tr>
					<td align="right">项目状态：</td>
					<td><input id="status" name="status" class="mini-combobox" textField="text" valueField="id" data="statusTypes" style="width:80%" /></td>
					<td align="right"></td>
					<td></td>
				</tr>

				<!-- 如果是单数就补充缺失部分 -->
			</table>
		</div>
		<div property="footer" style="text-align:center;padding:5px;padding-right:15px;">
			<a class="mini-button" iconCls="icon-save" onClick="doSave()">保存</a>
			<a class="mini-button" iconCls="icon-cancel" onClick="cancel()">取消</a>
		</div>
	</div>
</body>

<script type="text/javascript">
	statusTypes = [
		{ id: 1, text: "有效" },
		{ id: 2, text: "结束" }
	];

	projectTypes = [
		{ id: 1, text: "在建项目" },
		{ id: 2, text: "研发项目" },
		{ id: 3, text: "投标项目" }
	];

	miniInit();

	var queryForm = new mini.Form("#queryForm");
	var detailForm = new mini.Form("#detailForm");
	var win = mini.get("detailWin");

	var datagrid = mini.get("datagrid");
	datagrid.set({
		url: http.getUrl("/oa/project/project/page.do"),
		columns: [
			{ type: "indexcolumn", width: 20 },
			{ field: "projectNo", width: 60, headerAlign: "center", header: "项目编号" },
			{ field: "projectName", width: 200, headerAlign: "center", header: "项目名称" },
			{ field: "projectType", width: 100, headerAlign: "center", header: "项目性质", type: "comboboxcolumn", editor: { type: "combobox", data: projectTypes } },
			{ field: "status", width: 100, headerAlign: "center", header: "项目状态", type: "comboboxcolumn", editor: { type: "combobox", data: statusTypes } },
			{ field: "startTime", width: 100, headerAlign: "center", dateFormat: "yyyy-MM-dd", header: "项目开始时间" },
			{ field: "endTime", width: 100, headerAlign: "center", dateFormat: "yyyy-MM-dd", header: "项目结束时间" },
			{ field: "projectUserName", width: 100, headerAlign: "center", header: "技术经理" },
			{ field: "documentUserName", width: 100, headerAlign: "center", header: "文档管理员" }
		]
	});
	var orderByString = "";

	// 表单与表格绑定数据
	var db = new mini.DataBinding();
	db.bindForm("detailForm", datagrid);

	doSearch();

	function doSearch() {
		var data = queryForm.getData(true, false);
		if (orderByString != "") {
			data["orderBy"] = orderByString;
		}
		datagrid.load(data, null, miniui.showLoadErrorMessageBox);
	}

	// 新增污染物
	function doAdd() {
		datagrid.clearSelect(false);
		detailForm.reset();
		win.setTitle("新增机构");
		win.showAtPos('center', 'middle');
	}

	// 修改污染物
	function doEdit() {
		if (datagrid.getSelected()) {
			debugger
			win.setTitle("修改机构数据");
			win.showAtPos('center', 'middle');
			var data = datagrid.getSelected();
			mini.get("projectUserID").setValue(data.projectUserID);
			mini.get("projectUserName").setText(data.projectUserName);
			mini.get("documentUserID").setValue(data.documentUserID);
			mini.get("documentUserName").setText(data.documentUserName);
		} else {
			mini.alert("请选中需要修改的数据行", "提示", null);
		}
	}

	// 保存污染物
	function doSave() {
		if (!detailForm.validate()) {
			return;
		}
		mini.mask({
			el: document.body,
			cls: 'mini-mask-loading',
			html: '数据保存中...'
		});
		var data = detailForm.getData(true);
		http.post(http.getUrl("/oa/project/project/save.do"), data, function (page) {
			mini.unmask();
			win.hide();
			mini.alert("保存成功", "提示", null);
			datagrid.reload();
		});
	}

	function cancel() {
		win.hide();
	}

	// 删除用户
	function doDelete() {
		if (datagrid.getSelected() == null) {
			mini.alert("请选中需要删除的数据行", "提示", null);
			return;
		}

		mini.confirm("确认删除该数据信息吗？", "删除操作", function (e) {
			if (e == "ok") {
				mini.mask({
					el: document.body,
					cls: 'mini-mask-loading',
					html: '数据删除中...'
				});
				var ids = datagrid.getSelected().projectID;
				var data = {
					"projectID": ids
				};
				http.post(http.getUrl("/oa/project/project/delete.do"), data, function (page) {
					mini.unmask();
					win.hide();
					mini.alert("删除成功", "提示", null);
					datagrid.reload();
				});
			}
		});
	}

	function openSelectUserDialog(e) {
		var field = e.source;
		// debugger
		mini.open({
			url: ctx + '/page/system/win_user_select.html',
			title: "选择员工",
			width: 650,
			height: 550,
			onload: function () {
				var data = e.source.text;
				if (data != "") {
					var iframe = this.getIFrameEl();
					// iframe.contentWindow.setData(data);
				}
			},
			ondestroy: function (action) {
				if (action == "ok") {
					var iframe = this.getIFrameEl();

					var data = iframe.contentWindow.getData();
					data = mini.clone(data); //必须

					var name = e.source.name;
					if (name == "projectUserName") {
						debugger
						mini.get("projectUserID").setValue(data.userID);
						mini.get("projectUserName").setText(data.userName);
					} else if (name == "documentUserName") {
						mini.get("documentUserID").setValue(data.userID);
						mini.get("documentUserName").setText(data.userName);
					}
				}
			}
		});
	}

	function doOrg() {
		if (datagrid.getSelected() == null) {
			mini.alert("请选中需要操作的数据行", "提示", null);
			return;
		}
		var data = datagrid.getSelected();
		// debugger
		mini.open({
			url: ctx + '/page/work/org.html',
			title: "组织管理",
			width: 800,
			height: 600,
			onload: function () {
				var iframe = this.getIFrameEl();
				iframe.contentWindow.setData(data);
			}
		});
	}
</script>

</html>